<template>
  <!-- 级联组件 -->
  <el-cascader size="mini" style="width:300px" :value="value" :options="treeData" :props="propr" separator="-" @change="changeValue" />
</template>

<script>
import { transListToTreeData } from '@/utils/index'
import { getDepartment } from '@/api/department'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      treeData: [], // 列表数据
      propr: {
        label: 'name', // 要展示的字段
        value: 'id' // 要获取的是id
      }
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      this.treeData = await transListToTreeData(await getDepartment(), 0)
    },
    changeValue(list) {
      if (list.length > 0) {
        this.$emit('input', list[list.length - 1])
      }
    }
  }
}
</script>

<style>

</style>
